{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c04054f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy\n",
    "import pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5addd460",
   "metadata": {},
   "source": [
    "# Series"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1053c495",
   "metadata": {},
   "source": [
    "- Series是一种类似于一维数组的数据结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d9e0f94c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "语文        100\n",
       "数学        150\n",
       "英语        100\n",
       "Python    130\n",
       "Pandas    150\n",
       "Numpy     150\n",
       "dtype: int64"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "s = pandas.Series({'语文':100,'数学':150,'英语':100,'Python':130,'Pandas':150,'Numpy':150})\n",
    "display(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "44eb0a6b",
   "metadata": {},
   "source": [
    "- shape 形状\n",
    "- size 长度\n",
    "- index 索引\n",
    "- values 值\n",
    "- name 名字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "40cdc0cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "s.shape\n",
    "s.size\n",
    "s.index\n",
    "s.values\n",
    "s.name # 如果有name，那么会显示name，如果没有则什么都不会显示"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "372ec227",
   "metadata": {},
   "source": [
    "- head() 查看前几条数据，默认5条\n",
    "- tail() 查看后几条数据，默认5条"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "4d296c74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "数学        150\n",
       "英语        100\n",
       "Python    130\n",
       "Pandas    150\n",
       "Numpy     150\n",
       "dtype: int64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.head()\n",
    "s.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2bb715e1",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad045d5a",
   "metadata": {},
   "source": [
    "检测缺失数据\n",
    "- pandas.isnull()\n",
    "- pandas.notnull()\n",
    "- isnull()\n",
    "- notnull()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "d8a27786",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     张三\n",
       "1     李四\n",
       "2     王五\n",
       "3    NaN\n",
       "dtype: object"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "s = pandas.Series(['张三','李四','王五',numpy.nan]) # nan表示空值\n",
    "display(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "02f16b39",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     True\n",
       "1     True\n",
       "2     True\n",
       "3    False\n",
       "dtype: bool"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.isnull() # 如果为空，会判断为True\n",
    "# pandas.isnull(s)\n",
    "s.notnull() # 如果不是空，会判断为True\n",
    "# pandas.notnull(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed005827",
   "metadata": {},
   "source": [
    "- 过滤掉空值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "bc56593f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    张三\n",
       "1    李四\n",
       "2    王五\n",
       "dtype: object"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cand1 = s.isnull()\n",
    "cand1\n",
    "# 取反\n",
    "~cand1\n",
    "s[~cand1]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
